//
//  AppDelegate.m
//  GoldBook
//
//  Created by wmz on 2020/10/23.
//  Copyright © 2020 wmz. All rights reserved.
//

#import "AppDelegate.h"
#import "QuDanMainTabBarController.h"
#if __has_include(<Bugly/Bugly.h>)
#import <Bugly/Bugly.h>
#endif
#if __has_include(<TUICore/TUILogin.h>)
#import <TUICore/TUILogin.h>
#endif
#ifdef DEBUG
#if __has_include(<Bagel/Bagel.h>)
#import <Bagel/Bagel.h>
#endif
#endif

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [self setUpConfigWithOptions:launchOptions];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = QuDanMainTabBarController.new;
    [self.window makeKeyAndVisible];
    return YES;
}
/// 配置
- (void)setUpConfigWithOptions:(NSDictionary *)launchOptions{
#ifdef DEBUG
#if __has_include(<Bagel/Bagel.h>)
    if (@available(iOS 13, *)) {
        //[Bagel start];
    }
#endif
#endif
#if __has_include(<TUICore/TUILogin.h>)
    [TUILogin initWithSdkAppID:1400572052];
#endif
    
#if __has_include(<Bugly/Bugly.h>)
    [Bugly startWithAppId:@"cc9c4cc272"];
#endif
    
    [WXApi registerApp:PAY_WX_APP_ID universalLink:@"https://zb.zuan8lm.com/"];
    [UIApplication sharedApplication].statusBarStyle =  UIStatusBarStyleLightContent;
    [[NSUserDefaults standardUserDefaults] setValue:@(NO) forKey:@"_UIConstraintBasedLayoutLogUnsatisfiable"];
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options{
    /// 支付宝回调
    if ([url.host isEqualToString:@"safepay"]) {
        [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
            if (self.ZFBCallBack) self.ZFBCallBack(resultDic);
        }];
        return YES;
    } else {
        return [WXApi handleOpenURL:url delegate:_wxDelegate];
    }
}

-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return UIInterfaceOrientationMaskPortrait;//默认全局不支持横屏
}

@end
